package cn.flying.cloud.file.web;

import javax.annotation.Resource;

import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.file.core.ocr.service.OCRService;

/**
 * OCR操作相关请求处理服务
 *
 * @author: admin
 * @date: 2025年07月29日 11:08
 * @version: 1.0
 */
@RestController
@RequestMapping("/file/ocr")
public class OCRController {

    @Resource
    private OCRService ocrService;

    /**
     * 上传文件并OCR识别
     *
     * @param file        文件
     * @param bucketName  桶
     * @param ocrType     OCR类别
     * @param serviceCode 服务码
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/uploadAndOcr", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Rt<?> uploadAndOcr(@RequestParam("file") MultipartFile file, @RequestParam("bucket") String bucketName, @RequestParam("ocrType") Integer ocrType, String serviceCode) throws Exception {
        Map<String, Object> map = ocrService.ocrAllInOne(file, bucketName, ocrType, serviceCode);
        return Rt.success(map);
    }

    /**
     * OCR识别
     *
     * @param file    文件
     * @param ocrType OCR类别
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/ocrAllInOne", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Rt<?> ocrAllInOne(@RequestParam("file") MultipartFile file, @RequestParam("ocrType") Integer ocrType) throws Exception {
        Map<String, Object> map = ocrService.ocrAllInOne(file, ocrType);
        return Rt.success(map);
    }
}
